package fr.jee.ejb.model;

import java.io.Serializable;
import java.lang.Integer;
import java.lang.String;
import java.util.Date;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.eclipse.persistence.annotations.Index;

@Entity
@Table(name = "utilisateur")
@TableGenerator(name = "SEQUENCE_UTILISATEUR", initialValue = 0, table = "sequence", pkColumnName = "code", valueColumnName = "valeur", allocationSize = 1)
public class Utilisateur implements Serializable {

	@Id
	@Column(name = "id")
	@GeneratedValue(strategy = GenerationType.TABLE, generator = "SEQUENCE_UTILISATEUR")
	private Integer id;

	@Index
	@Size(max = 255)
	@NotNull
	@Column(name = "mail", length = 255, nullable = false)
	private String mail;

	@Size(max = 128)
	@NotNull
	@Column(name = "password", length = 128, nullable = false)
	private String password;

	@Index
	@Size(max = 50)
	@NotNull
	@Column(name = "nom", length = 50, nullable = false)
	private String nom;

	@Index
	@Size(max = 50)
	@NotNull
	@Column(name = "prenom", length = 50, nullable = false)
	private String prenom;

	@Size(max = 20)
	@Column(name = "token_modification_password", length = 20, nullable = true)
	private String tokenModificationPassword;

	@NotNull
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "date_creation", nullable = false)
	private Date dateCreation;

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "date_modification_password", nullable = true)
	private Date dateModificationPassword;

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "date_derniere_connexion", nullable = true)
	private Date dateDerniereConnexion;

	@NotNull
	@ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.LAZY)
	@JoinColumn(name = "ref_profil", nullable = false)
	private Profil profil;

	public Utilisateur() {
	}

	public String getNomPrenom() {
		return String.format("%s %s", nom, prenom);
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getMail() {
		return mail;
	}

	public void setMail(String mail) {
		this.mail = mail;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getNom() {
		return nom;
	}

	public void setNom(String nom) {
		this.nom = nom;
	}

	public String getPrenom() {
		return prenom;
	}

	public void setPrenom(String prenom) {
		this.prenom = prenom;
	}

	public String getTokenModificationPassword() {
		return tokenModificationPassword;
	}

	public void setTokenModificationPassword(String tokenModificationPassword) {
		this.tokenModificationPassword = tokenModificationPassword;
	}

	public Date getDateCreation() {
		return dateCreation;
	}

	public void setDateCreation(Date dateCreation) {
		this.dateCreation = dateCreation;
	}

	public Date getDateModificationPassword() {
		return dateModificationPassword;
	}

	public void setDateModificationPassword(Date dateModificationPassword) {
		this.dateModificationPassword = dateModificationPassword;
	}

	public Date getDateDerniereConnexion() {
		return dateDerniereConnexion;
	}

	public void setDateDerniereConnexion(Date dateDerniereConnexion) {
		this.dateDerniereConnexion = dateDerniereConnexion;
	}

	public Profil getProfil() {
		return profil;
	}

	public void setProfil(Profil profil) {
		this.profil = profil;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}
		if (obj == this) {
			return true;
		}
		if (obj.getClass() != getClass()) {
			return false;
		}
		Utilisateur other = (Utilisateur) obj;
		return new EqualsBuilder().append(id, other.id).isEquals();
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder(17, 37).append(id).toHashCode();
	}

	@Override
	public String toString() {
		return new ToStringBuilder(this).append("id", id).toString();
	}

}
